<?php

class TagnewsController extends Zend_Controller_Action {

    function init() {
        
    }

    function indexAction() {

        $intTagID = $this->_request->getParam('id',0);
        $strTagName = $this->_request->getParam('tagname','');

        //init page
        $intPage = $this->_request->getParam('page',1);

        //Get model News instance
        $newsModel = News::getInstance();

        //Set start offset
        $perpage = LIMIT_NEW_MORE;
        $intStart = ($intPage - 1) * $perpage;

        //Get List ID ArticleID
        $arrListIDNews = $newsModel->getListArticleByTag($intTagID,$perpage,$intStart);
        
        $arrDataNews = array();

        $intTotal = 0;

        //Check Data
        if(!empty($arrListIDNews['data']))
        {
            //Loop Data
            foreach($arrListIDNews['data'] as $articleID)
            {
                if($articleID>0)
                {
                    $arrDataNews[] = $newsModel->getDetailArticle($articleID);
                }
            }

            $intTotal = $arrListIDNews['total'];
        }

        $intTotalPage = ceil($intTotal / $perpage);

        $strUri = '/'.$strTagName.'/tag-'.$intTagID;

        //InitParam Paging
        $arrParamPaging = array(
            'total'         =>  $intTotal,
            'page'          =>  $intPage,
            'uri'           =>  $strUri,
            'showItem'      =>  3,
            'perpage'       =>  $perpage,
            'idPagination'  =>  'pagination',
            'extEnd'        =>  '.html',
            'separate'      =>  '-'
        );

        /* Assign to view*/
        $this->view->arrDataNews = $arrDataNews;
        $this->view->total = $intTotal;
        $this->view->arrParamPaging = $arrParamPaging;
    }

}